package com.bluedot.monitor.impl;

import com.bluedot.message.Message;
import com.bluedot.monitor.Monitor;
import com.bluedot.queue.InQueue;
import com.bluedot.queue.impl.ControllerServiceQueue;

/**
 * 监听controllerServiceQueue中消息的monitor<br/>
 * 在监听到队列有新消息后通过message携带的信息反射调用目标service的目标方法
 */
public class ControllerServiceQueueMonitor extends Monitor {

    private final InQueue queue;

    /**
     * 初始化要监听的队列
     */
    private ControllerServiceQueueMonitor() {
        queue = ControllerServiceQueue.getInstance();
    }

    /**
     * monitorThreadPool线程池中运行的task
     */
    @Override
    public void run() {
        while (true) {
            Message message = queue.poll();
            // 通过message携带的信息反射调用目标service的目标方法
        }
    }

    public static ControllerServiceQueueMonitor getInstance() {
        return MonitorHolder.controllerServiceQueueMonitor;
    }

    private static class MonitorHolder {

        private static final ControllerServiceQueueMonitor controllerServiceQueueMonitor = new ControllerServiceQueueMonitor();
    }
}
